<table border="1" id="time_input_table">
  <tr align="center" style="background:#ddd;">
    <td>
      <div style="position:relative;height:25px;">
        <div style="top:3px;left:20px;width:200px;font-size:1.5em;">
          <%= @this_year %>/<%= @month_names[@this_month-1]%>/<%=@this_day%><br/>
        </div>
      </div>
    </td>
    <td><%=l(:work_time)%></td>
    <td><%=l(:field_activity)%></td>
    <td><%=l(:field_comments)%></td>
    <% @custom_fields.each do |cf| %>
       <td><%= cf.name %></td>
    <% end %>
  </tr>
<%
@day_pack[:odr_prjs].each do |prj_pack|
  next if prj_pack[:ref_issues].length==0
  prj = prj_pack[:prj]
  next if !prj.visible?
  dsp_prj = prj.id
  dsp_pos = prj_pack[:odr]

  activities = []
  activity_default = nil
  prj.activities.each do |act|
    activities.push([act.name, act.id])
    activity_default = act.id if act.is_default
  end
%>
<tr style="background:#000;color:#fff;">
  <td>
      <%if @this_uid==@crnt_uid then%>

        <a href="JavaScript:prj_pos('<%=url_for(@link_params) %>',<%=dsp_prj%>,<%=dsp_pos%>,<%=@prj_odr_max+((dsp_pos.to_i<0)?1:0)%>);">
          <%= (dsp_pos.to_i<0) ? "*" : dsp_pos %>
        </a>
     <%end%>
        <%=prj.name%>
  </td>
  <td><%=sprintf("%1.1f", prj_pack[:total])%></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <% @custom_fields.each do |cf| %>
     <td>&nbsp;</td>
  <% end %>
</tr>
<%
prj_pack[:odr_issues].each do |issue_pack|
  issue = issue_pack[:issue]
  issue_id = issue.nil? ? -1 : issue.id
  issue_odr = issue_pack[:odr].to_i
  issue_color = issue_pack[:worked] ? "#cfc" : "#fff"
  issue = Issue.find_by_id(issue_id)
  if issue.nil? || !issue.visible? then
    issueHtml = "<del>Issue:"+issue_id.to_s+"</del>"
  elsif issue.closed?
    issueHtml = "<del>"+issue.to_s+"</del>" 
  else
    issueHtml = issue.to_s
  end

  if issue_pack[:each_entries].length==0 then
%>
<!-- 工数エントリなし -->
<tr id="time_entry_pos[<%=issue_id%>][0]">
  <td style="background:<%=issue_color%>;">
  <div style="position:relative;width:300px;">
    <%if @this_uid==@crnt_uid then%>
    <a href="JavaScript:ticket_pos('<%=url_for(@link_params) %>',<%=issue_id%>,<%=issue_odr%>,<%=@issue_odr_max+((issue_odr.to_i<0)?1:0)%>);">
      <%= (issue_odr.to_i<0) ? "*" : issue_odr %>
    </a>
    <%end%>

    <%= link_to(issueHtml, {:controller=>"issues", :action=>"show", :id=>issue_id}, :popup=>true) %>
    <%= print_issue_cost(issue) %>
    <%if @this_uid==@crnt_uid then%>
    <a name="<%='done_ratio'+issue.id.to_s%>"
        href="JavaScript:update_done_ratio(
          '<%=url_for(@link_params.merge(:action=>"popup_update_done_ratio"))%>',
          '<%=url_for(@link_params.merge(:action=>"ajax_update_done_ratio"))%>',
          <%=issue_id%>);">
      [<%=issue.done_ratio%>&#37;]
    </a>
    &nbsp;&nbsp;&nbsp;
    <a style="position:absolute;bottom:1px;right:10px;" href="JavaScript:dup_ticket('<%=url_for(@link_params.merge(:action=>"ajax_insert_daily"))%>',
                                   'time_entry_pos[<%=issue_id%>][0]',
                                    <%=issue_id%>);">+</a>
      <%if issue_odr>0 then%>
      <a style="position:absolute;bottom:1px;right:3px;" href="<%=url_for(@link_params.merge(:ticket_del=>issue_id))%>">x</a>
      <%end%>
    <%else%>
      [<%=issue.done_ratio%>&#37;]
    <%end%>
  </div>
  </td>
  <td>
    <%= text_field_tag("new_time_entry["+issue_id.to_s+"][0][hours]", "", :size=>5) %>
  </td>
  <td>
    <%= select_tag "new_time_entry["+issue_id.to_s+"][0][activity_id]", options_for_select(activities,activity_default), :required => true %>
  </td>
  <td>
    <%= text_field_tag("new_time_entry["+issue_id.to_s+"][0][comments]", "", :size=>80)%>
  </td>
  <%@custom_fields.each do |cf|
    def cf.custom_field
      return self
    end
    def cf.value
      return self.default_value
    end
    def cf.true?
      return self.default_value
    end
    def cf.customized
      nil
    end
  %>
     <td><%= custom_field_tag "new_time_entry["+issue_id.to_s+"][0]", cf %></td>
  <% end %>
</tr>
<%
  else
    issue_pack[:each_entries].each do |hour_id, hour|
%>
<!-- 工数エントリあり -->
<tr id="time_entry_pos<%=hour_id%>">
  <td style="background:<%=issue_color%>;">
  <div style="position:relative;width:300px;">
  <%if !issue.nil? then%>
    <%if @this_uid==@crnt_uid then%>
    <a href="JavaScript:ticket_pos('<%=url_for(@link_params) %>',<%=issue_id%>,<%=issue_odr%>,<%=@issue_odr_max+((issue_odr.to_i<0)?1:0)%>);">
      <%= (issue_odr.to_i<0) ? "*" : issue_odr %>
    </a>
    <%end%>
    <%= link_to(issueHtml, {:controller=>"issues", :action=>"show", :id=>issue_id}, :popup=>true) %>

    <%= print_issue_cost(issue) %>
    <%if @this_uid==@crnt_uid then%>
    <a name="<%='done_ratio'+issue_id.to_s%>"
        href="JavaScript:update_done_ratio(
          '<%=url_for(@link_params.merge(:action=>"popup_update_done_ratio"))%>',
          '<%=url_for(@link_params.merge(:action=>"ajax_update_done_ratio"))%>',
          <%=issue_id%>);">
      [<%=issue.done_ratio%>&#37;]
    </a>
    &nbsp;&nbsp;&nbsp;

    <a style="position:absolute;bottom:1px;right:10px;" href="JavaScript:dup_ticket('<%=url_for(@link_params.merge(:action=>"ajax_insert_daily"))%>',
                                   'time_entry_pos<%=hour_id%>',
                                    <%=issue_id%>);">+</a>
      <%if issue_odr>0 then%>
        <a style="position:absolute;bottom:1px;right:3px;" href="<%=url_for(@link_params.merge(:ticket_del=>issue_id))%>">x</a>
      <%end%>
    <%else%>
      [<%=issue.done_ratio%>&#37;]
    <%end%>
  <%end%>
  </div>
  </td>
  <td>
    <%= text_field_tag("time_entry["+hour_id.to_s+"][hours]", hour.hours, :size=>5) %>
  </td>
  <td>
    <%= select_tag "time_entry["+hour_id.to_s+"][activity_id]", options_for_select(activities, hour.activity_id), :required => true %>
  </td>
  <td>
    <%= text_field_tag("time_entry["+hour_id.to_s+"][comments]", hour.comments, :size=>80)%>
  </td>
  <% @custom_fields.each do |cf|
    cfv = hour.custom_field_values.detect {|v| v.custom_field_id == cf.id}
    def cf.customized; nil; end;
  %>
     <td><%= custom_field_tag "time_entry["+hour_id.to_s+"]", cfv %></td>
  <% end %>
</tr>
<%
   end
  end
 end
end
%>
<% if @day_pack[:other]!=0 then %>
<tr style="background:#000;color:#fff;">
  <td>private</td>
  <td><%=sprintf("%1.1f", @day_pack[:other])%></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <% @custom_fields.each do |cf| %>
     <td>&nbsp;</td>
  <% end %>
</tr>
<% end %>
<tr align="center" id="time_input_table_bottom" style="background:#ddd;">
  <td>&nbsp;</td>
  <td><%=sprintf("%1.1f", @day_pack[:total])%></td>
  <td>&nbsp;</td>
  <td>&nbsp;</td>
  <% @custom_fields.each do |cf| %>
     <td>&nbsp;</td>
  <% end %>
</tr>
</table>
